All files / web/src/app/practice/[studentId]/session/[sessionId] page.tsx

0% Statements 0/65
0% Branches 0/1
0% Functions 0/1
0% Lines 0/65

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                                                                                                                   
import { notFound } from 'next/navigation'
import { canPerformAction } from '@/lib/classroom/access-control'
import {
  getPracticeStudent,
  getRecentSessionResults,
  getSessionPlan,
} from '@/lib/curriculum/server'
import { getUserId } from '@/lib/viewer'
import { SummaryClient } from '../../summary/SummaryClient'

// Disable caching for this page - session data should be fresh
export const dynamic = 'force-dynamic'

interface SessionPageProps {
  params: Promise<{ studentId: string; sessionId: string }>
}

/**
 * Session Page - View a specific historical session
 *
 * URL: /practice/[studentId]/session/[sessionId]
 *
 * Shows the results of a specific practice session by ID.
 * Used when viewing session history from the dashboard.
 */
export default async function SessionPage({ params }: SessionPageProps) {
  const { studentId, sessionId } = await params

  // Fetch player, session, and problem history in parallel
  const [player, session, problemHistory] = await Promise.all([
    getPracticeStudent(studentId),
    getSessionPlan(sessionId),
    getRecentSessionResults(studentId, 100),
  ])

  // 404 if player doesn't exist
  if (!player) {
    notFound()
  }

  // Check authorization - user must have view access to this player
  const viewerId = await getUserId()
  const hasAccess = await canPerformAction(viewerId, studentId, 'view')
  if (!hasAccess) {
    notFound() // Return 404 to avoid leaking existence of player
  }

  // 404 if session doesn't exist or belongs to different player
  if (!session || session.playerId !== studentId) {
    notFound()
  }

  // Calculate average seconds per problem from the session
  const avgSecondsPerProblem = session.avgTimePerProblemSeconds ?? 40

  return (
    <SummaryClient
      studentId={studentId}
      player={player}
      session={session}
      avgSecondsPerProblem={avgSecondsPerProblem}
      problemHistory={problemHistory}
    />
  )
}